const log4js = require('log4js');
// const fs = require('fs')

const logPath = `${global._root}/logs/app.log`;

// const logPathDir = `${global._root}/logs`
// if (!fs.existsSync(logPathDir)) {
//     fs.mkdirSync(logPathDir, { recursive: true })
// }

log4js.configure({
  appenders: {
    app: {
      type: process.env.DEV === 'true' ? 'console' : 'file',
      // type: 'dateFile',
      filename: logPath,
      daysToKeep: 30,
    },
  },
  categories: {
    default: {
      appenders: ['app'],
      level: 'debug',
      enableCallStack: true,
    },
  },
});

const logger = log4js.getLogger('default');

module.exports = logger;
